const path = require('path');
const { override, addWebpackAlias, fixBabelImports, addLessLoader, removeModuleScopePlugin, babelInclude, adjustStyleLoaders } = require('customize-cra');

module.exports = override(
    addWebpackAlias({
        ['@']: path.resolve(__dirname, 'src')
    }),
    fixBabelImports('import', {
        libraryName: 'antd',
        libraryDirectory: 'es',
        style: true // 设置为true时，将导入less而不是css
    }),
    addLessLoader({
        lessOptions: {
            javascriptEnabled: true,
            modifyVars: {
                '@primary-color': '#a61f38'
            }
        }
    }),
    adjustStyleLoaders((rule => {
        if (rule.test.toString().includes('scss')) {
            rule.use.forEach((item) => {
                if (item.loader && item.loader.includes('sass-loader')) {
                    // item.options.prependData = `$prefix-cls: 'sui-';$primary-color: #a61f38;`
                }
            });
        }
    })),
    removeModuleScopePlugin(),
    babelInclude([
        path.resolve('src')
    ])
);
